﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.MainModule.Entities;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.GroupBranches;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests.RepositoriesTests
{
    [TestClass()]
    public class GroupBranchRepositoryTest : RepositoryTestsBase<GroupBranch>
    {
       string groupBranchName = "Group Branch Name";
       
       public override System.Linq.Expressions.Expression<Func<GroupBranch, bool>> FilterExpression
        {
            get { return a => a.GroupBranchId == TestConstants.Instance.GROUP_BRANCH_ID; }
        }

        public override System.Linq.Expressions.Expression<Func<GroupBranch, Guid>> OrderByExpression
        {
            get { return a => a.GroupBranchId; }
        }
		
		[TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindGroupBranch_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IGroupBranchRepository repository = new GroupBranchRepository(context,traceManager);

            //Act
            repository.FindGroupBranch(null);
        }
			
		#region GroupBranchGroupBranchIdSpecification	
			
		[TestMethod()]
        public void FindGroupBranch_Invoke_InvalidGroupBranchIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IGroupBranchRepository repository = new GroupBranchRepository(context, traceManager);

			Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            GroupBranchGroupBranchIdSpecification spec = new GroupBranchGroupBranchIdSpecification(invalidId);

            //Act
            GroupBranch groupBranch = repository.FindGroupBranch(spec);

            //Assert
            Assert.IsNull(groupBranch);
        }
		
        [TestMethod()]
        public void FindGroupBranchByGroupBranchId_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IGroupBranchRepository repository = new GroupBranchRepository(context, traceManager);

            GroupBranchGroupBranchIdSpecification spec = new GroupBranchGroupBranchIdSpecification(TestConstants.Instance.GROUP_BRANCH_ID);

            //Act
            GroupBranch groupBranch = repository.FindGroupBranch(spec);

            //Assert
            Assert.IsNotNull(groupBranch);
        }
		
		#endregion

		#region GroupBranchNamePrioritySpecification
		
		[TestMethod()]
        public void FindGroupBranch_Invoke_InvalidGroupBranchNameReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IGroupBranchRepository repository = new GroupBranchRepository(context, traceManager);

			string invalidName = "invalid name";
            GroupBranchNamePrioritySpecification spec = new GroupBranchNamePrioritySpecification(invalidName);

            //Act
            IEnumerable<GroupBranch> groupBranch = repository.FindGroupBranches(spec);

            //Assert
            Assert.IsNotNull(groupBranch);
            Assert.IsTrue(groupBranch.Count() == 0);
        }
		
		[TestMethod()]
        public void FindGroupBranchByGroupBranchName_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IGroupBranchRepository repository = new GroupBranchRepository(context, traceManager);

            GroupBranchNamePrioritySpecification spec = new GroupBranchNamePrioritySpecification(groupBranchName);

            //Act
            IEnumerable<GroupBranch> groupBranch = repository.FindGroupBranches(spec);

            //Assert
            Assert.IsNotNull(groupBranch);
            Assert.IsTrue(groupBranch.Count() > 0);
        }
		
		#endregion
    }
}
